package com.yn.admin.zy;

import com.yn.common.constants.Constants;
import com.yn.common.model.system.SystemGroupData;
import com.yn.common.page.BasePage;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.request.sc.SystemGroupDataRequest;
import com.yn.common.request.sc.SystemGroupDataSearchRequest;
import com.yn.common.response.sc.BaseResult;
import com.yn.service.service.SystemGroupDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName: ShareController
 * @Description:
 * @Author: lxp
 * @Date: 2025/5/9 15:56
 **/
@Api(tags = "推广分享相关接口")
@RestController
@RequestMapping("/share")
public class ShareController {
    @Resource
    private SystemGroupDataService systemGroupDataService;

    /**
     * 分页获取海报数据
     * @param status 数据状态
     * @param pageParamRequest 分页参数
     */
    @ApiOperation(value = "分页获取海报数据")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseResult<BasePage<SystemGroupData>> getList(@RequestParam(value = "status",required = false)
                                                        @ApiParam(value = "状态（1：开启；2：关闭；）",required = false)
                                                         Boolean status,
                                                         @Validated PageParamRequest pageParamRequest) {
        SystemGroupDataSearchRequest request = new SystemGroupDataSearchRequest();
        request.setGid(Constants.GROUP_DATA_ID_SPREAD_BANNER_LIST);
        request.setStatus(status);

        BasePage<SystemGroupData> systemGroupDataCommonPage = BasePage.restPage(systemGroupDataService.getList(request, pageParamRequest));
        return BaseResult.success(systemGroupDataCommonPage);
    }

    /**
     * 新增海报数据
     * @param systemGroupDataRequest SystemFormCheckRequest 新增参数
     */
    @ApiOperation(value = "新增海报数据")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public BaseResult<String> save(@RequestBody @Validated SystemGroupDataRequest systemGroupDataRequest) {
        systemGroupDataRequest.setGid(Constants.GROUP_DATA_ID_SPREAD_BANNER_LIST);
        if (systemGroupDataService.create(systemGroupDataRequest)) {
            return BaseResult.success();
        }
        return BaseResult.failed();
    }

    /**
     * 删除海报数据
     * @param id Integer
     */
    @ApiOperation(value = "删除海报数据")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public BaseResult<String> delete(@RequestParam(value = "id") Integer id) {
        if (systemGroupDataService.removeById(id)) {
            return BaseResult.success();
        }
        return BaseResult.failed();
    }

    /**
     * 修改海报数据
     * @param id integer id
     * @param request 修改参数
     */
    @ApiOperation(value = "修改海报数据")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public BaseResult<String> update(@RequestParam Integer id, @RequestBody @Validated SystemGroupDataRequest request) {
        request.setGid(Constants.GROUP_DATA_ID_SPREAD_BANNER_LIST);
        if (systemGroupDataService.update(id, request)) {
            return BaseResult.success();
        }
        return BaseResult.failed();
    }

    /**
     * 海报数据详情信息
     * @param id Integer
     */
    @ApiOperation(value = "海报数据详情信息")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public BaseResult<SystemGroupData> info(@RequestParam(value = "id") Integer id) {
        SystemGroupData systemGroupData = systemGroupDataService.getById(id);
        return BaseResult.success(systemGroupData);
    }
}
